package com.zzl.boot.bigevent.controller;

import com.zzl.boot.bigevent.pojo.category;
import com.zzl.boot.bigevent.pojo.result;
import com.zzl.boot.bigevent.service.categoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Validated
@CrossOrigin//允许跨区请求
public class categoryController {
    @Autowired
    private categoryService service;
    //添加
    @PostMapping()
    public result addCategory(@RequestBody @Validated(category.add.class) category category) {
        //System.out.println(category);
        service.addCategory(category);
        return result.success();
    }
    //获取分类列表
    @GetMapping()
    public result<List<category>> getAllCategory() {
        List<category> allCategory = service.getAllCategory();
        //System.out.println(allCategory);
        return result.success(allCategory);
    }
    //获取文章列表详情
    @GetMapping("/detail")
    public result<category> getCategoryDetail( Integer id) {
        category category = service.getCategoryDetail(id);
        //System.out.println(category);
        return result.success(category);
    }
    //更新文章列表详情
    @PutMapping()
    public result updateCategory(@RequestBody @Validated(category.update.class) category category) {
        //System.out.println(category);
        service.updateCategory(category);
        return result.success();
    }
    //删除
    @DeleteMapping("/del")
    public result deleteCategory(@RequestParam Integer id) {

        return  service.delById(id);
    }
}
